﻿using Approval.Domain;
using Approval.Infrastructure.Interface;
using Approval.ReadAPI.Appliaction.Command.HCTReationCommand;
using MediatR;
using PublicCommon;

namespace Approval.ReadAPI.Appliaction.CommandHandler.HCTReationCommandHandler
{
    public class HCTReationListCommandHandler : IRequestHandler<HCTReationListCommand, List<HCTRelation>>
    {
        private readonly IHCTRelationRepository hCTRelationRepository;

        public HCTReationListCommandHandler(IHCTRelationRepository hCTRelationRepository)
        {
            this.hCTRelationRepository = hCTRelationRepository;
        }

        public async Task<List<HCTRelation>> Handle(HCTReationListCommand request, CancellationToken cancellationToken)
        {
            var res = await hCTRelationRepository.GetListInfo(x => x.HCTId.Equals(request.HCTId));
            var list =  res.OrderByDescending(x =>x.Id);
            return list.ToList();
        }
    }
}
